/*****************坐标投影转换部分******************/
//这是从3度带转到经纬度
function GetConvertZBC(zbs, IServerUrl) {
    var url = IServerUrl + "/CoordSysTranslatorComponent/restjsr/CoordSysTranslator/32718/21413/";
    var data = "";
    for (var i = 0; i < zbs.length; i++) {
        data += "{'y':" + zbs[i].y + ",'x':" + zbs[i].x + "},";
    }
    if (data != "") {
        data = data.substr(0, data.length - 1);
    }
    data += ".rjson";
    url += data;
    var resptext = callService(url);
    var obj = JSON.parse(resptext);
    if (obj != null && obj.length > 0)
        return obj;
    else
        return zbs;
}
function callService(url) {
    var commit = getcommit();
    var method = "GET";
    var async = false;
    var user = "";
    var password = "";
    var entry = null;
    commit.open(method, encodeURI(url), async, user, password);
    commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    commit.send(entry);
    return commit.responseText;
}
function getcommit() {
    var commit = null;
    try {
        commit = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (ex) {
        try {
            commit = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (ex) {
            this.commit = null;
        }
    }
    if (!commit && typeof XMLHttpRequest != "undefined") {
        commit = new XMLHttpRequest();
    }
    return commit;
}

/******************/
function sfMarker() {
    this.x = 0;
    this.y = 0;
    this.title = "";
    this.key = '';
}
function sfPoint(x, y) {
    this.x = x;
    this.y = y;
}
/*
方法说明：地图类
参数说明：
1、divid：div的ID
返回值：无
*/
function sfMap(divid) {
    var _self = this;
    //添加到临时层的对象的风格
    var style = { strokeColor: "green",
        strokeWidth: 2,
        pointerEvents: "visiblePainted",
        fillColor: "lightblue",
        fillOpacity: 0.2
    };
    var style2 = { strokeColor: "blue",
        strokeWidth: 2,
        pointerEvents: "visiblePainted",
        fillColor: "lightblue",
        fillOpacity: 0.2
    };
    this.beforeClearMaps = null;
    this.markerInIconUrl = baseurlmapjs + "../resource/controlImages/tm.png";
    this.markerOutIconUrl = baseurlmapjs + "../resource/controlImages/tm.png";
    this.markerBackgroundImageUrl = baseurlmapjs + '../resource/controlImages/markers.png';
    this.measuredistanceimg = baseurlmapjs + "../resource/controlImages/ruler.png";
    this.measureareaimg = baseurlmapjs + "../resource/controlImages/area.ico";
    this.panimgurl = baseurlmapjs + "../resource/controlImages/openhand.png";
    this.clearimgurl = baseurlmapjs + "../resource/controlImages/brush.png";
    //量算的回调函数，包含两个参数，第一个是量算的结果值，是数字类型，第二个参数是结果值的单位，字符串型，如“米","平方米"
    var measureCallback = null;
    //量算需要有一个服务地址，在添加第一个图层（不包括矢量层和标记层）的时候自动将图层的url赋给这个变量，所以如果地图中有SuperMap图层的话不需要设置该变量值
    this.measureURL = "";
    //是否添加了矢量图层
    this.isVectorLayerAdded = false;
    //是否添加了标记图层
    this.isMarkerLayerAdded = false;
    //定位点的时候所放到的级别
    this.locatePointZoom = 3;
    //地图变量
    this.map = null;
    //是否启用鼠标滚轮
    this._bmouseWheelEnable = false;
    //地图控件div的ID
    this._mapdivid = '';
    //图层管理器控件div的ID
    this._layercontroldivid = '';
    //矢量图层
    this.vectorLayer = null;
    //标记图层
    this.markerLayer = null;
    //画点对象
    this._drawPoint = null;
    //画线对象
    this._drawLine = null;
    //画面对象
    this._drawPolygon = null;
    //点查询URL
    this.pointQueryURL = "";
    //点查询数据集
    this.pointQueryDtName = "";
    //点查询回调函数
    this.pointQueryCallBack = "";
    //要添加的图层数和添加成功后的图层数
    var layersToAdd = 0;
    var layersAdded = 0;
    //加载的地图图层初始化完成后触发的事件
    this.afterBaseLayersInit = null;
    //初始化地图  
    if (divid != null && divid != '') {
        this._mapdivid = divid;
        _self.vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
        _self.vectorLayer.style = style;
        _self._drawPoint = new SuperMap.Control.DrawFeature(_self.vectorLayer, SuperMap.Handler.Point);
        _self._drawLine = new SuperMap.Control.DrawFeature(_self.vectorLayer, SuperMap.Handler.Path);
        _self._drawPolygon = new SuperMap.Control.DrawFeature(_self.vectorLayer, SuperMap.Handler.Polygon);
        _self._drawPoint.events.on({ "featureadded": drawPointConpleted });
        _self._drawLine.events.on({ "featureadded": drawLineConpleted });
        _self._drawPolygon.events.on({ "featureadded": drawPolygonConpleted });
        this.map = new SuperMap.Map
	    (divid, { controls: [new SuperMap.Control.MousePosition(),
	                new SuperMap.Control.Navigation({ documentDrag: false, zoomWheelEnabled: false, enableKinetic: true }),
	                new SuperMap.Control.ScaleLine(),
	                new SuperMap.Control.KeyboardDefaults(),
	    	        new SuperMap.Control.TouchNavigation({ dragPanOptions: { zoomWheelEnabled: false, enableKinetic: true} }),
	    	        new SuperMap.Control.PanZoomBar({ forceFixedZoomLevel: true, showSlideBar: true }), _self._drawPoint, _self._drawLine, _self._drawPolygon], allOverlays: true
	    });
        document.onkeydown = dokeydown;
        document.onkeyup = dokeyup;
        this.map.units = 'm';
        _self.vectorLayer.events.on({ "layerInitialized": function () { alert("xx");} });
//        this.map.addLayer(_self.vectorLayer);
//        _self.isVectorLayerAdded = true;
    }
    function dokeydown(e) {
        if (!_self._bmouseWheelEnable) { var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which; if (code == "16") { _self.map.controls[1].enableZoomWheel(); } }
    }
    function dokeyup(e) {
        if (!_self._bmouseWheelEnable) { var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which; if (code == "16") { _self.map.controls[1].disableZoomWheel(); } }
    }
    function queryFailed(e) {
        alertex("d");
    }


    /**********移除所有图层**********************/
    this.removeAllLayers = function () {

        this.clearMaps();
        for (var i = _self.map.layers.length - 1; i >= 0; i--) {
            _self.map.removeLayer(_self.map.layers[i]);
        }
        _self.isVectorLayerAdded = false;
        _self.isMarkerLayerAdded = false;
    }

    /**********量算距离和面积Start,外部接口：measureDistance***********/
    this.measureDistance = function (callback) {
        if (!_self.isVectorLayerAdded) {
            addVectorLayer();
        }
        if (callback != null) measureCallback = callback;
        else measureCallback = null;
        _self.setActionPan();
        _self._drawLine.activate();
    }
    function drawLineConpleted(drawGeometryArgs) {
        measureComplete(drawGeometryArgs);
    }
    this.measureArea = function () {
        if (!_self.isVectorLayerAdded) {
            addVectorLayer();
        }
        _self.setActionPan();
        _self._drawPolygon.activate();
    }
    function drawPolygonConpleted(drawGeometryArgs) {
        measureComplete(drawGeometryArgs);
    }
    function measureComplete(drawGeometryArgs) {
        var geometry = drawGeometryArgs.feature.geometry,
               measureParam = new SuperMap.REST.MeasureParameters(geometry), /* MeasureParameters：量算参数类。 客户端要量算的地物间的距离或某个区域的面积*/
               myMeasuerService = new SuperMap.REST.MeasureService(_self.measureURL); //量算服务类，该类负责将量算参数传递到服务端，并获取服务端返回的量算结果
        myMeasuerService.events.on({ "processCompleted": calculateCompleted });

        //对MeasureService类型进行判断和赋值，当判断出是LineString时设置MeasureMode.DISTANCE，否则是MeasureMode.AREA
        if (geometry.CLASS_NAME.indexOf("LineString") > -1) {
            myMeasuerService.measureMode = SuperMap.REST.MeasureMode.DISTANCE;
        } else {
            myMeasuerService.measureMode = SuperMap.REST.MeasureMode.AREA;
        }
        myMeasuerService.processAsync(measureParam); //processAsync负责将客户端的量算参数传递到服务端。
        _self.setActionPan();
    }

    function calculateCompleted(measureEventArgs) {
        var distance = measureEventArgs.result.distance,
            area = measureEventArgs.result.area,
            unit = measureEventArgs.result.unit;
        if (distance != -1) {
            if (measureCallback != null) measureCallback(distance, "米");
            else doMapAlert("量算结果", distance.toString().substring(0, distance.toString().indexOf(".") + 3) + "米");
        } else if (area != -1) {
            if (measureCallback != null) measureCallback(area, "平方米");
            else
                doMapAlert("量算结果", area.toString().substring(0, area.toString().indexOf(".") + 3) + "平方米");
        }
    }

    function doMapAlert(tip, mess, success) {
        if ($('#mapAlert').size()) {
            $('div').remove('#mapAlert');
        }
        if (tip) {
            tip += '：';
        }
        var x = $("#" + _self._mapdivid).offset().left;
        var y = $("#" + _self._mapdivid).offset().top;
        var width = $("#" + _self._mapdivid).width();
        var width2 = width / 2;
        width = width / 4;
        x += width;
        y += 20;

        if (!success) {
            var htmlString = '<div id="mapAlert" class="alert alert-success fade in" style="position:absolute; top: ' + y + 'px; left:' + x + 'px; width:' + width2 + 'px; z-index: 2000; text-align: center;">'
                    + '<button class="close" data-dismiss="alert">&times;</button>'
                    + '<strong>' + tip + '</strong>' + mess
                    + '</div>';
        } else {
            var htmlString = '<div id="mapAlert" class="alert alert-error fade in" style="position:absolute;top: ' + y + 'px; left:' + x + 'px; width:' + width2 + 'px; z-index: 2000;text-align: center;">'
                    + '<button class="close" data-dismiss="alert">&times;</button>'
                    + '<strong>' + tip + '</strong>' + mess
                    + '</div>';
        }

        $('#' + _self._mapdivid).append($(htmlString));
        $("#mapAlert .close")[0].onclick = function () { $('div').remove('#mapAlert'); }
    }

    /**********量算距离和面积End***********/

    /**********隐藏比例尺调节控件****************/
    this.hideNavigation = function () {
        for (var i = 0; i < _self.map.controls.length; i++) {
            if (_self.map.controls[i].CLASS_NAME == "SuperMap.Control.PanZoomBar") {
                _self.map.controls[i].deactivate();
                _self.map.controls[i].destroy();
                break;
            }
        }
    }


    /**********隐藏坐标信息****************/
    this.hidePosition = function () {
        for (var i = 0; i < _self.map.controls.length; i++) {
            if (_self.map.controls[i].CLASS_NAME == "SuperMap.Control.MousePosition") {
                _self.map.controls[i].deactivate();
                break;
            }
        }
    }

    /********************点查询START，外部接口：queryByPoint*****************************/
    this.queryByPoint = function (queryurl, dtname, afterquerycallback) {
        _self.setActionPan();
        _self.pointQueryURL = queryurl;
        _self.pointQueryDtName = dtname;
        _self.pointQueryCallBack = afterquerycallback;
        if (afterquerycallback != null) {
            afterQueryCallBack = afterquerycallback;
        }
        if (!_self.isVectorLayerAdded) {
            addVectorLayer();
        }
        _self._drawPoint.activate();
    }
    function drawPointConpleted(drawGeometryArgs) {
        var feature = new SuperMap.Feature.Vector();
        feature.geometry = drawGeometryArgs.feature.geometry;
        var queryParam, queryByGeometryParameters, queryService;
        queryParam = new SuperMap.REST.FilterParameter({ name: _self.pointQueryDtName });
        queryByGeometryParameters = new SuperMap.REST.QueryByGeometryParameters({
            queryParams: [queryParam],
            geometry: drawGeometryArgs.feature.geometry,
            spatialQueryMode: SuperMap.REST.SpatialQueryMode.WITHIN
        });
        queryService = new SuperMap.REST.QueryByGeometryService(_self.pointQueryURL, {
            eventListeners: {
                "processCompleted": pointQueryComplete,
                "processFailed": queryFailed,
                "oripoint": feature.geometry
            }
        });
        queryService.processAsync(queryByGeometryParameters);
        _self.vectorLayer.removeAllFeatures();
    }
    function pointQueryComplete(queryEventArgs) {
        var i, j, feature,
        result = queryEventArgs.result;
        if (result && result.recordsets) {
            for (i = 0; i < result.recordsets.length; i++) {
                if (result.recordsets[i].features) {
                    for (j = 0; j < result.recordsets[i].features.length; j++) {
                        feature = result.recordsets[i].features[j];
                        feature.style = style;
                        _self.vectorLayer.addFeatures(feature);
                    }
                }
            }
        }
        if (_self.pointQueryCallBack != null) {
            _self.pointQueryCallBack(queryEventArgs);
        }
    }
    /********************点查询END*****************************/



    this.setActionPan = function () {
        _self._drawPoint.deactivate();
        _self._drawLine.deactivate();
        _self._drawPolygon.deactivate();
    }

    /*------------------------方法组--------------------------*/
    //显示量算距离和量算面积的工具条
    this.showToolbar = function () {
        var x = $("#" + this._mapdivid).offset().left + 2;
        var y = $("#" + this._mapdivid).offset().top;
        var html = "<div style=' filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);background:-webkit-gradient(linear,0% 0%, 0% 100%, from(#ffffff), to(#cecfde));width:120px;height:30px;position:absolute;left:" + x + "px;top:" + y + "px;z-index:300003'>\
	    <p title='量算距离' class='pclass_mytoolbar' id='id_ptoolbar_measuredis' style='float:left;margin-left:10px;background:url(" + this.measuredistanceimg + ");margin-right: 3px;background-position: 6px 4px;\
margin-top: 6px;border: 1px solid rgb(204, 204, 204);-webkit-border-radius: 4px;background-repeat: no-repeat;width:20px;height:20px;display;block'></p>\
 <p title='量算面积'  class='pclass_mytoolbar' id='id_ptoolbar_measurearea'  style='float:left;background:url(" + this.measureareaimg + ");margin-right: 3px;background-position: 3px 2px;\
margin-top: 6px;border: 1px solid rgb(204, 204, 204);-webkit-border-radius: 4px;background-repeat: no-repeat;width:20px;height:20px;display;block'></p>\
 <p title='平移'  class='pclass_mytoolbar' id='id_ptoolbar_pan'  style='float:left;background:url(" + this.panimgurl + ");margin-right: 3px;background-position: 1px 1px;\
margin-top: 6px;border: 1px solid rgb(204, 204, 204);-webkit-border-radius: 4px;background-repeat: no-repeat;width:20px;height:20px;display;block'></p>\
 <p  title='清空量算层' class='pclass_mytoolbar' id='id_ptoolbar_clear'  style='float:left;background:url(" + this.clearimgurl + ");margin-right: 3px;background-position: 3px 2px;\
margin-top: 6px;border: 1px solid rgb(204, 204, 204);-webkit-border-radius: 4px;background-repeat: no-repeat;width:20px;height:20px;display;block'></p></div>";
        $("#" + this._mapdivid).append(html);
        $(".pclass_mytoolbar").css("cursor", "pointer");
        $(".pclass_mytoolbar").hover(function () { $(this).css('border', '1px solid gray'); }, function () { $(this).css('border', '1px solid rgb(204, 204, 204)'); });
        $("#id_ptoolbar_measuredis").click(function () { _self.measureDistance(); });
        $("#id_ptoolbar_measurearea").click(function () { _self.measureArea(); });
        $("#id_ptoolbar_pan").click(function () { _self.setActionPan(); });
        $("#id_ptoolbar_clear").click(function () {
            if (_self.beforeClearMaps != null) {
                _self.beforeClearMaps();
            }
            _self.clearMapsByTag();
        });
    }



    //设置定位到点的时候的缩放级别，从0到9
    this.setZoomForLoacatePoint = function (zoomlevel) {
        _self.locatePointZoom = zoomlevel;
    }
    this.setScales = function (scales) {
        _self.map.scales = scales;
    }
    //移动拖动条的位置
    this.movePanZoomControl = function (x, y) {
        var i = 0;
        for (i = 0; i < _self.map.controls.length; i++) {
            if (_self.map.controls[i].CLASS_NAME == "SuperMap.Control.PanZoomBar") {
                var div = _self.map.controls[i].div;
                var top = div.style["top"];
                var left = div.style["left"];
                var newtop = y;
                var newleft = x;
                if (top != null && top != '')
                    newtop += parseInt(y + parseInt(top));
                if (left != null && left != '')
                    newleft += parseInt(x + parseInt(left));
                div.style["top"] = newtop + "px";
                div.style["left"] = newleft + "px";
                div.style["zoom"] = 0.9;
            }
        }
    }
    this.enableMouseWheel = function () {
        _self._bmouseWheelEnable = true; ;
        _self.map.controls[1].enableZoomWheel();
    }
    this.disableMouseWheel = function () {
        _self._bmouseWheelEnable = false;
        _self.map.controls[1].disableZoomWheel();
    }
    //添加一个图层
    this.addLayer = function (layerurl, layername, layerindex, layervisible) {
        //判断当前地图中是否已经存在该图层
        if (_self.map.layers.length > 0) {
            for (var i = 0; i < _self.map.layers.length; i++) {
                if (_self.map.layers[i].url == layerurl) {
                    return;
                }
            }
        }
        return addLayerInner(layerurl, layername, layerindex, layervisible);
    }
    //添加多个图层
    this.addLayers = function (layers) {
        if (layers != null && layers.length > 0) {
            for (var i = 0; i < layers.length; i++) {
                addLayerInner(layers[0].url, layers[0].name, layers[0].index, layers[0].visible);
            }
        }
    }
    //添加图层的内部函数
    function addLayerInner(layerurl, layername, layerindex, layervisible) {
        if (layername == null || layername == '') layername = getpurename(layerurl);
        var layer = new SuperMap.Layer.TiledDynamicRESTLayer(layername, layerurl, { transitionEffect: "resize", transparent: true, cacheEnabled: true });
        layer.scales = _self.map.scales;
        layer.addOptions({ userindex: layerindex });
        if (layervisible == false)
            layer.setVisibility(layervisible);
        layer.events.on({ "layerInitialized": afterLayerInitialized });
        return layer;
    }
    //图层初始化好后触发的事件
    function afterLayerInitialized(e, index) {
        var index = e.getOptions()["userindex"];
        var length = _self.map.layers == null ? 0 : _self.map.layers.length;
        var isBaseLayer = false;
        //如果还没有图层，直接插入，如果有了MarkerLayer或者VectorLayer，插入到MarkerLayer和VectorLayer的下面
        if (length == 0) {
            _self.map.addLayer(this);
            _self.measureURL = this.url;
            isBaseLayer = true;
        }
        else {
            while (_self.map.layers[length - 1] != null && (_self.map.layers[length - 1].name == "Marker Layer" || _self.map.layers[length - 1].name == "Vector Layer")) {
                length--;
            }
            if (_self.map.baseLayer == null || length == 0) {
                isBaseLayer = true; index = 0;
                _self.measureURL = this.url;
            }
            _self.map.addLayer(this);
            //如果指定了索引，设置索引
            if (index != null) {
                _self.map.setLayerIndex(this, index);
            }
            else {
                _self.map.setLayerIndex(this, length);
            }
        }
        //如果是第一个图层，设置一下以最大范围显示
        if (_self.map.layers.length == 1) {
            _self.map.zoomToMaxExtent(false);
        }
        //刷新图层管理器
        if (_self._layercontroldivid != null && _self._layercontroldivid != '') {
            _self.showLayersControl(_self._layercontroldivid);
        }
        if (isBaseLayer) {
            if (this.maxExtent.left < -180 || this.maxExtent.right > 180 || this.maxExtent.top > 90 || this.maxExtent.bottom < -90) {
                _self.map.units = 'm';
            }
            if (_self.afterBaseLayersInit != null) {
                _self.afterBaseLayersInit();
            }
        }
    }
    //添加矢量图层
    function addVectorLayer() {
        _self.map.addLayer(_self.vectorLayer);
        _self.isVectorLayerAdded = true;
    }
    //添加标记图层
    function addMarkerLayer() {
        _self.markerLayer = new SuperMap.Layer.Markers("Marker Layer");
        _self.map.addLayer(_self.markerLayer);
        _self.isMarkerLayerAdded = true;
    }

    //查询并显示到矢量图层----内部使用的方法
    function query(dtname, serviceurl, sqlfilter, succeedCallBack, failedCallBack, idname, options) {
        if (this.vectorLayer != null) {
            this.vectorLayer.removeAllFeatures();
        }
        if (_self.markerLayer != null) {
            _self.clearMapsByTag(""); // markerLayer.clearMarkers();
        }
        var queryParam, queryBySQLParams, queryBySQLService;
        queryParam = new SuperMap.REST.FilterParameter({ name: dtname, attributeFilter: sqlfilter }),
        queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({ queryParams: [queryParam] }),
        queryBySQLService = new SuperMap.REST.QueryBySQLService(serviceurl, {
            eventListeners: { "processCompleted": succeedCallBack, "processFailed": failedCallBack }, options: options, idname: idname
        });
        queryBySQLService.processAsync(queryBySQLParams);
    }
    function processFailed(e) {
        alertex("查询出错");
    }
    //根据sql 查询并在矢量图层显示---外部方法
    this.queryBySql = function (dtname, serviceurl, sqlfilter, bzoom) {
        if (bzoom == null) bzoom = false;
        var options = { "bzoom": bzoom };
        query(dtname, serviceurl, sqlfilter, queryProcessCompleted, processFailed, "XZQDM", options);
    }
    //查询成功事件
    function queryProcessCompleted(queryEventArgs) {
        if (!_self.isVectorLayerAdded) {
            addVectorLayer();
        }
        var bzoom = false;
        if (queryEventArgs.object.options != null) {
            bzoom = queryEventArgs.object.options.bzoom;
        }
        _self.vectorLayer.destroyFeatures();
        var i, j, feature,
        result = queryEventArgs.result;
        var bounds = null;
        if (result && result.recordsets) {
            for (i = 0; i < result.recordsets.length; i++) {
                if (result.recordsets[i].features) {
                    for (j = 0; j < result.recordsets[i].features.length; j++) {
                        feature = result.recordsets[i].features[j];
                        feature.style = style;
                        _self.vectorLayer.addFeatures(feature);
                        if (bounds == null)
                            bounds = feature.geometry.bounds;
                        else
                            bounds = bounds.extend(featrue.geometry.bounds);
                    }
                }
            }
        }
        if (bzoom && bounds != null) {
            _self.map.zoomToExtent(bounds);
        }
    }
    //根据SQL标记
    this.markerBySql = function (dtname, serviceurl, sqlFilter, idname, options) {
        query(dtname, serviceurl, sqlFilter, markerProcessCompleted, processFailed, idname, options);
    }

    //定位点、线、面的时候地图的比例尺？？？？
    //标记成功事件
    function markerProcessCompleted(queryEventArgs) {
        if (!_self.isVectorLayerAdded) {
            addVectorLayer();
        }
        if (!_self.isMarkerLayerAdded) {
            addMarkerLayer();
        }

        var mkincbk = null;
        var mkoutcbk = null;
        var mkclickcbk = null;
        var bsmfield = "SmID";
        if (queryEventArgs.object.options != null && queryEventArgs.object.options.mkmousein != null) {
            mkincbk = queryEventArgs.object.options.mkmousein;
            mkoutcbk = queryEventArgs.object.options.mkmouseout;
            mkclickcbk = queryEventArgs.object.options.mkmouseclick;
            bsmfield = queryEventArgs.object.idname;
        }

        //用来唯一标识marker的字段名称
        var i, j, feature,
        result = queryEventArgs.result;
        var bounds = new SuperMap.Bounds;

        var bdw = false;
        if (result.recordsets != null && result.recordsets.length == 1 && result.recordsets[0].features != null && result.recordsets[0].features.length == 1
        && result.recordsets[0].features[0].geometry.CLASS_NAME == "SuperMap.Geometry.Point") {
            bdw = true;
            var bs = _self.map.getExtent();
            _self.map.setCenter(new SuperMap.LonLat(result.recordsets[0].features[0].geometry.x, result.recordsets[0].features[0].geometry.y), _self.map.getZoom(), false, false);
        }

        if (result && result.recordsets) {
            for (i = 0; i < result.recordsets.length; i++) {
                if (result.recordsets[i].features) {

                    for (j = 0; j < result.recordsets[i].features.length; j++) {
                        feature = result.recordsets[i].features[j];
                        var point = feature.geometry.getCentroid();
                        var bo = feature.geometry.getBounds();
                        bounds.extend(bo);
                        var size = new SuperMap.Size(28, 34);
                        var offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
                        var icon = new SuperMap.Icon(_self.markerOutIconUrl, size, offset);
                        var marker = new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon);
                        marker.events.element.setAttribute("tag", j);
                        var strtitle = '';
                        for (k = 0; k < result.recordsets[i].fieldCaptions.length; k++) {
                            if (result.recordsets[i].fieldCaptions[k].substr(0, 2) != 'Sm') {
                                strtitle += result.recordsets[i].fieldCaptions[k] + ":" + feature.attributes[result.recordsets[i].fieldCaptions[k]] + "\r";
                            }
                        }
                        if (strtitle.length > 0) {
                            strtitle = strtitle.substr(0, strtitle.length - 1);
                        }
                        marker.events.element.setAttribute("tag", strtitle);
                        marker.events.element.setAttribute("BSM", feature.attributes[bsmfield]);
                        marker.icon.imageDiv.style["cursor"] = "pointer";
                        marker.icon.imageDiv.innerHTML = '<P style="margin-left:0;margin-top:0;color:white;font-weight:bold;font-size:17px"></P>'; //'+(j+1)+'</P>';
                        _self.markerLayer.addMarker(marker);

                        marker.events.on({ "mouseover": markerMouseIn });
                        marker.events.on({ "mouseout": markerMouseOut });

                        marker.events.on({ "mouseover": mkincbk });
                        marker.events.on({ "mouseout": mkoutcbk });
                        marker.events.on({ "mousedown": mkclickcbk });
                        marker.icon.imageDiv.style["backgroundImage"] = "url(" + _self.markerBackgroundImageUrl + ")";
                        if (result.recordsets[i].features.length > 10) {
                            marker.icon.imageDiv.style["backgroundPositionX"] = 1;
                            marker.icon.imageDiv.style["background-position"] = "1px 0";
                        }
                        else {
                            switch (SuperMap.Browser.name) {
                                case "chrome":
                                    marker.icon.imageDiv.style["background-position"] = "0px 0px"; //-j*34+"px 0px";
                                    break;
                                case "msie":
                                    marker.icon.imageDiv.style["backgroundPositionX"] = "0"; //-j*34;
                                    marker.icon.imageDiv.style["backgroundPositionY"] = "0";
                                    break;
                                case "opera":
                                    break;
                                case "firefox":
                                    marker.icon.imageDiv.style["backgroundPosition"] = "0px 0px"; //-j*34+"px 0px";
                                    break;
                                case "mozilla":
                                    break;
                            }

                        }
                    }
                }
            }
        }
        if (!bdw) {
            var bs = 2;
            var wid = bounds.right - bounds.left;
            var hei = bounds.top - bounds.bottom;
            var dwid = wid / bs;
            var dhei = hei / bs;
            bounds.left = bounds.left - dwid;
            bounds.right = bounds.right + dwid;
            bounds.top = bounds.top + dhei;
            bounds.bottom = bounds.bottom - dhei;
            _self.map.zoomToExtent(bounds, false);
        }
    }
    var m_fun = null;
    this.addMarkers = function (sfmarkers, fun) {
        m_fun = fun;

        if (!_self.isMarkerLayerAdded) {
            addMarkerLayer();
        }
        _self.markerLayer.clearMarkers();
        var bounds = new SuperMap.Bounds;
        var bdw = false;
        if (sfmarkers.length == 1) {
            if (sfmarkers[0].x != null && sfmarkers[0].x != '')
                _self.map.setCenter(new SuperMap.LonLat(sfmarkers[0].x, sfmarkers[0].y), _self.map.getZoom(), false, false);
            bdw = !bdw;
        }
        _self.onSelect = fun;
        for (j = 0; j < sfmarkers.length; j++) {

            var sfmarker = sfmarkers[j];
            if (sfmarker.x != null && sfmarker.x != '') {
                bounds.extend(new SuperMap.LonLat(sfmarker.x, sfmarker.y));
                var size = new SuperMap.Size(28, 34);
                var offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
                var icon = new SuperMap.Icon(_self.markerOutIconUrl, size, offset);
                var marker = new SuperMap.Marker(new SuperMap.LonLat(sfmarker.x, sfmarker.y), icon);
                marker.events.on({ "mouseover": markerMouseIn });
                marker.events.on({ "mouseout": markerMouseOut });
                marker.events.on({ "mousedown": markerMouseDwown });
                marker.events.element.setAttribute("tag", sfmarker.key);
                marker.events.element.setAttribute("title", sfmarker.title);
                marker.icon.imageDiv.style["cursor"] = "pointer";
                var py = 9;
                if (j > 8) py = 4
                marker.icon.imageDiv.innerHTML = '<P style="margin-left:' + py + 'px;margin-top:0px;color:white;font-weight:bold;font-size:14px">' + sfmarker.key + '</P>';
                _self.markerLayer.addMarker(marker);
                marker.icon.imageDiv.style["backgroundImage"] = "url(" + _self.markerBackgroundImageUrl + ")";
                switch (SuperMap.Browser.name) {
                    case "chrome":
                        marker.icon.imageDiv.style["background-position"] = "0px 0px"; //-j*34+"px 0px";
                        break;
                    case "msie":
                        marker.icon.imageDiv.style["backgroundPositionX"] = "0"; //-j*34;
                        marker.icon.imageDiv.style["backgroundPositionY"] = "0";
                        break;
                    case "firefox":
                        marker.icon.imageDiv.style["backgroundPosition"] = "0px 0px"; //-j*34+"px 0px";
                        break;
                }
            }

        }
        if (!bdw && sfmarkers != null && sfmarkers.length > 0) {
            bounds = bounds.scale(2);
            _self.map.zoomToExtent(bounds, true);
        }
    }
    //marker鼠标进入事件
    function markerMouseIn(e, obj) {
        var instmarker = obj == null ? this : obj;
        switch (SuperMap.Browser.name) {
            case "chrome":
                instmarker.icon.imageDiv.style["backgroundPositionY"] = "-73px";
                break;
            case "msie":
                instmarker.icon.imageDiv.style["backgroundPositionY"] = "-73px";
                break;
            case "opera":
                break;
            case "firefox":
                var pxy = instmarker.icon.imageDiv.style["backgroundPosition"];
                var index = pxy.indexOf(" ");
                var p_x = pxy.substr(0, index);
                instmarker.icon.imageDiv.style["backgroundPosition"] = p_x + " -73px";
                break;
            case "mozilla":
                break;
        }
        var sizenew = new SuperMap.Size(instmarker.icon.size.w, instmarker.icon.size.h + 2);
        instmarker.icon.setSize(sizenew);

    }
    function markerMouseDwown(e, obj) {
        if (m_fun != null) {
            m_fun();
        }
    }

    //marker鼠标离开事件
    function markerMouseOut(e, obj) {
        var instmarker = obj == null ? this : obj;
        var sizenew = new SuperMap.Size(instmarker.icon.size.w, instmarker.icon.size.h - 2);
        instmarker.icon.setSize(sizenew);
        switch (SuperMap.Browser.name) {
            case "chrome":
                instmarker.icon.imageDiv.style["backgroundPositionY"] = "0px";
                break;
            case "msie":
                instmarker.icon.imageDiv.style["backgroundPositionY"] = "0";
                break;
            case "opera":
                break;
            case "firefox":
                var pxy = instmarker.icon.imageDiv.style["backgroundPosition"];
                var index = pxy.indexOf(" ");
                var p_x = pxy.substr(0, index);
                instmarker.icon.imageDiv.style["backgroundPosition"] = p_x + " -0px";
                break;
            case "mozilla":
                break;
        }
        instmarker.icon.imageDiv.style["backgroundPositionY"] = 0;
    }
    this.removePopups = function () {
        if (_self.map.popups != null && _self.map.popups.length > 0) {
            var index = _self.map.popups.length - 1;
            for (index = _self.map.popups.length - 1; index >= 0; index--) {
                _self.map.popups[index].destroy();
            }
        }
    }

    function popupclose() {
        this.destroy();
    }

    //外部调用高亮某个Marker的方法
    this.markermousein = function (key) {
        if (_self.markerLayer != null) {
            for (i = 0; i < _self.markerLayer.markers.length; i++) {
                if (_self.markerLayer.markers[i].events.element.getAttribute("BSM") == key) {
                    markerMouseIn(null, _self.markerLayer.markers[i]);
                    return _self.markerLayer.markers[i];
                    break;
                }
            }
        }
    }
    //外部调用去掉某个Marker高亮的方法
    this.markermouseout = function (key) {
        if (_self.markerLayer != null && _self.markerLayer.markers != null) {
            for (i = 0; i < _self.markerLayer.markers.length; i++) {
                if (_self.markerLayer.markers[i].events.element.getAttribute("BSM") == key) {
                    markerMouseOut(null, _self.markerLayer.markers[i]);
                    return _self.markerLayer.markers[i];
                    break;
                }
            }
        }
    }
    //定位到某个Marker
    this.locateMarker = function (key) {
        if (_self.markerLayer != null && _self.markerLayer.markers != null) {
            for (i = 0; i < _self.markerLayer.markers.length; i++) {
                if (_self.markerLayer.markers[i].events.element.getAttribute("BSM") == key) {
                    _self.map.panTo(_self.markerLayer.markers[i].lonlat);
                    return _self.markerLayer.markers[i];
                }
            }
        }
    }

    //获取文件名
    function getpurename(str) {
        var index = str.lastIndexOf("/");
        var strres = str.substr(index + 1, str.length - index - 1);
        return strres;
    }
    this.showLayersControl = function (controldivid) {
        _self._layercontroldivid = controldivid;
        var ele = document.getElementById(controldivid);
        if (ele != null) {
            $(ele).find("ul").remove();
            var strhtml = '';
            strhtml += '<ul style="margin-top:17px;list-style:none">';
            var ids = new Array();
            for (i = _self.map.layers.length - 1; i >= 0; i--) {
                if (_self.map.layers[i].CLASS_NAME != "SuperMap.Layer.Vector" && _self.map.layers[i].CLASS_NAME != "SuperMap.Layer.Markers") {

                    var vis = _self.map.layers[i].getVisibility();
                    ids[i] = _self.map.layers[i].id + "_" + i;
                    var cls = vis == true ? ' checked="checked" ' : '';
                    strhtml += '<li class="layercontrolli"><input type="checkbox" ' + cls + 'class="layercontrolimg ' + cls + '" vis="' + vis + '" id="' + ids[i] + '" tag="' + _self.map.layers[i].id + '" ></input><a class="layercontroltitle">' + _self.map.layers[i].name + '</a>\
	            </li>';
                }
            }
            $(ele).css("height", _self.map.layers.length * 50);
            strhtml += '</ul>';
            //ele.innerHTML=strhtml;
            $(ele).append(strhtml);
            for (i = 0; i < ids.length; i++) {
                document.getElementById(ids[i]).onclick = funchecked;
                try {
                    $("#id_div_layercontrolblock_" + i).draggable({ axis: 'x' }, { containment: 'parent' });
                    document.getElementById("id_div_layercontrolblock_" + i).ondrag = fundraged;
                }
                catch (e) {
                }
            }
        }
    }

    this.clearMaps = function () {
        if (_self.markerLayer != null) {
            _self.markerLayer.clearMarkers();
        }
        if (_self.vectorLayer != null) {
            _self.vectorLayer.removeAllFeatures();
        }
    }
    this.clearMapsByTag = function (tag) {
        var mytag = "";
        if (tag != null) mytag = tag;
        if (!_self.isVectorLayerAdded) {
        }
        else {
            for (var i = _self.vectorLayer.features.length - 1; i >= 0; i--) {
                if (mytag == null || mytag == "") {
                    if (_self.vectorLayer.features[i]["tag"] == null) {
                        //                        _self.vectorLayer.removeFeatures(_self.vectorLayer.features[i]);
                        _self.vectorLayer.features[i].destroy();
                    }
                }
                else {
                    if (_self.vectorLayer.features[i]["tag"] != null && _self.vectorLayer.features[i]["tag"] == mytag) {
                        //                        _self.vectorLayer.removeFeatures(_self.vectorLayer.features[i]);
                        _self.vectorLayer.features[i].destroy();
                    }
                }
            }
        }
        if (_self.isMarkerLayerAdded) {
            for (var i = _self.markerLayer.markers.length - 1; i >= 0; i--) {
                if (mytag == null || mytag == "") {
                    if (_self.markerLayer.markers[i]["tag"] == null) {
                        _self.markerLayer.removeMarker(_self.markerLayer.markers[i]);
                        //                        _self.markerLayer.markers[i].destroy();
                    }
                }
                else {
                    if (_self.markerLayer.markers[i]["tag"] != null && _self.markerLayer.markers[i]["tag"] == mytag) {
                        _self.markerLayer.removeMarker(_self.markerLayer.markers[i]);
                        //                        _self.markerLayer.markers[i].destroy();
                    }
                }
            }
        }

    }

    //图层控制部分的透明条和选中框
    function fundraged() {
        // alert(c);
        var layerid = this.getAttribute("tag");
        var left = this.style["left"];
        var wid = this.offsetWidth;
        var width = this.parentNode.offsetWidth;
        width = parseInt(width) - parseInt(wid);
        var bl = 1 - parseInt(left) / width;
        var op = _self.map.getLayer(layerid).opacity;
        switch (SuperMap.Browser.name) {
            case "msie":
                _self.map.getLayer(layerid).setOpacity(bl);
                break;
            case "chrome":
                _self.map.getLayer(layerid).div.style["opacity"] = bl;
                break;
        }
    }
    function funchecked() {
        var bb = this.getAttribute("vis");
        //        if(bb==true || bb=="true")
        //        {
        //           removeClass(this,"layervisible");
        //           addClass(this,"layerunvisible");
        //        }
        //        else
        //        {
        //            addClass(this,"layervisible");
        //           removeClass(this,"layerunvisible");
        //        } 
        var a = false;
        if (bb == true || bb == "true") a = false;
        else a = true;
        this.setAttribute("vis", a);

        _self.map.getLayer(this.getAttribute("tag")).setVisibility(a);
    }

    this.addGeometry = function (points, bNotClearPreObj)//sfPoint数组
    {
        _self.map.units = 'm';
        if (points != null && points.length > 0) {
            var i = 0;
            var lin = new SuperMap.Geometry.LinearRing();
            for (i = 0; i < points.length; i++) {
                var p = new SuperMap.Geometry.Point(points[i].x, points[i].y);
                lin.addComponent(p, i);
            }
            var geo = new SuperMap.Geometry.Polygon(lin);

            if (!_self.isVectorLayerAdded) {
                addVectorLayer();
            }
            else {
                if (bNotClearPreObj) {
                }
                else {
                    _self.vectorLayer.destroyFeatures();
                }
            }
            geo.calculateBounds()
            var feature = new SuperMap.Feature.Vector(geo);
            var features = new Array();
            feature.style = style;
            features[0] = feature;
            _self.vectorLayer.addFeatures(features);
            var bds = _self.map.getMaxExtent();

            var bounds = geo.bounds.scale(5);
            if (bds == null)
                bds = bounds;
            else
                bds.extend(bounds);
            if (bds.left < 0 || bds.left > bounds.left) {
                bds.left = bounds.left;
            }

            if (bds.right < bounds.right) {
                bds.right = bounds.right;
            }

            if (bds.top < bounds.top) {
                bds.top = bounds.top;
            }

            if (bds.bottom < 0) {
                bds.bottom = bounds.bottom;
            }
            _self.map.restrictedExtent = bds;
            _self.map.maxExtent = bds;
            _self.map.zoomToExtent(bounds, true);
        }
    }

    function addMarkerTemp(qks, tag) {
        if (!_self.isMarkerLayerAdded) {
            addMarkerLayer();
        }
        for (var i = 0; i < qks.length; i++) {
            var zbs = qks[i];
            for (var j = 0; j < zbs.length; j++) {
                var x = zbs[j].x;
                var y = zbs[j].y;
                var size = new SuperMap.Size(0, 0);
                var offset = new SuperMap.Pixel(-5, -13);
                var icon = new SuperMap.Icon(_self.markerOutIconUrl, size, offset);
                var marker = new SuperMap.Marker(new SuperMap.LonLat(x, y), icon);
                marker.icon.imageDiv.style["cursor"] = "pointer";
                marker.icon.imageDiv.innerHTML = '<P style="z-index:100001;margin-left:0;margin-top:0;color:red;font-weight:normal;font-size:13px">' + zbs[j].gdh + '</P>';
                _self.markerLayer.addMarker(marker);
                marker.icon.imageDiv.style["backgroundImage"] = "url(" + _self.markerBackgroundImageUrl + ")";
                marker.icon.imageDiv.style["background-position"] = "0px 0px"; //-j*34+"px 0px";
                marker["tag"] = tag;
            }
        }
    }
    function createStyle(color) {
        var colortemp = "green";
        if (color) colortemp = color;
        var styletemp = { strokeColor: colortemp,
            strokeWidth: 1,
            pointerEvents: "visiblePainted",
            fillColor: colortemp,
            fillOpacity: 0.4
        };
        return styletemp;
    }

    this.hideFeatureByTag = function (tag) {
        if (_self.vectorLayer) {
            var layer = _self.vectorLayer;
            if (layer.features) {
                for (var i = 0; i < layer.features.length; i++) {
                    if (_self.map.layers[0].features[i].tag == tag) {
                        var id = _self.map.layers[0].features[i].geometry.id;
                        $("[id='" + id + "']").css("display", "none");

                    }
                }
            }
        }
    }
    this.hideMarkerByTag = function (tag) {
        for (var i = 0; i < _self.map.layers[1].markers.length; i++) {
            if (_self.map.layers[1].markers[i].tag == tag) {
                _self.map.layers[1].markers[i].display(false);

            }
        }
    }

    this.showFeatureByTag = function (tag) {
        for (var i = 0; i < _self.map.layers[0].features.length; i++) {
            if (_self.map.layers[0].features[i].tag == tag) {
                var id = _self.map.layers[0].features[i].geometry.id;
                $("[id='" + id + "']").css("display", "block");

            }
        }
    }
    this.showMarkerByTag = function (tag) {
        for (var i = 0; i < _self.map.layers[1].markers.length; i++) {
            if (_self.map.layers[1].markers[i].tag == tag) {
                _self.map.layers[1].markers[i].display(true);

            }
        }
    }
    this.addGeometryEx = function (qks, color, tag)//sfPoint数组
    {
        var styletemp;
        if (color != null && color != "") {
            styletemp = createStyle(color); 
        }
        else styletemp = style;
        if (qks != null && qks.length > 0) {

            if (qks[0][0].x > 180)
                _self.map.units = 'm';
            var geo = null;
            for (var j = 0; j < qks.length; j++) {
                var points = qks[j];
                if (points != null && points.length > 0) {
                    var lin = new SuperMap.Geometry.LinearRing();
                    for (var i = 0; i < points.length; i++) {
                        var p = new SuperMap.Geometry.Point(points[i].x, points[i].y);
                        lin.addComponent(p, i);
                    }
                    if (geo == null) geo = new SuperMap.Geometry.Polygon(lin);
                    else geo.addComponent(lin);
                }
            }
            if (!_self.isVectorLayerAdded) {
                addVectorLayer();
            }
            else {
                //_self.vectorLayer.destroyFeatures();//不能清空临时层-2013年4月16日by刘树峰

            }
            geo.calculateBounds()
            var feature = new SuperMap.Feature.Vector(geo);
            var features = new Array();
            feature.style = styletemp;
            feature["tag"] = tag;
            features[0] = feature;
            _self.vectorLayer.addFeatures(features);
            //_self.vectorLayer.removeAllFeatures();
            var bds = _self.map.getMaxExtent();

            var bounds = geo.bounds.scale(1.4);
            if (bds == null)
                bds = bounds;
            else
                bds.extend(bounds);

            if (bds.left < 0 || bds.left > bounds.left) {
                bds.left = bounds.left;
            }

            if (bds.right < bounds.right) {
                bds.right = bounds.right;
            }

            if (bds.top < bounds.top) {
                bds.top = bounds.top;
            }

            if (bds.bottom < 0) {
                bds.bottom = bounds.bottom;
            }

            //_self.map.restrictedExtent=bds;//不能限制这个移动范围
            //_self.map.maxExtent = bds;
            _self.map.zoomToExtent(bds, true);
            addMarkerTemp(qks, tag);
        } else { //_self.vectorLayer.removeAllFeatures(); 
        }
    }
    this.locatePoint = function (x, y, bChangeScale) {
        if (!_self.isMarkerLayerAdded) {
            addMarkerLayer();
        }
        if (bChangeScale == null || bChangeScale == true) {
            _self.map.setCenter(new SuperMap.LonLat(x, y), _self.locatePointZoom, false, false);
        }
        else {
            _self.map.setCenter(new SuperMap.LonLat(x, y), _self.map.getZoom(), false, false);
        }
        var size = new SuperMap.Size(28, 34);
        var offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
        var icon = new SuperMap.Icon(_self.markerOutIconUrl, size, offset);
        var marker = new SuperMap.Marker(new SuperMap.LonLat(x, y), icon);
        marker.icon.imageDiv.style["cursor"] = "pointer";
        marker.icon.imageDiv.innerHTML = '<P style="margin-left:0;margin-top:0;color:white;font-weight:bold;font-size:17px"></P>'; //'+(j+1)+'</P>';
        _self.markerLayer.addMarker(marker);
        marker.icon.imageDiv.style["backgroundImage"] = "url(" + _self.markerBackgroundImageUrl + ")";
        if (1 > 10) {
            marker.icon.imageDiv.style["backgroundPositionX"] = 1;
            marker.icon.imageDiv.style["background-position"] = "1px 0";
        }
        else {
            switch (SuperMap.Browser.name) {
                case "chrome":
                    marker.icon.imageDiv.style["background-position"] = "0px 0px"; //-j*34+"px 0px";
                    break;
                case "msie":
                    marker.icon.imageDiv.style["backgroundPositionX"] = "0"; //-j*34;
                    marker.icon.imageDiv.style["backgroundPositionY"] = "0";
                    break;
                case "opera":
                    break;
                case "firefox":
                    marker.icon.imageDiv.style["backgroundPosition"] = "0px 0px"; //-j*34+"px 0px";
                    break;
                case "mozilla":
                    break;
            }
        }
    }
    this.addGeometryByTag = function (qks, tag)//sfPoint数组
    {

        if (qks != null && qks.length > 0) {
            if (qks[0][0].x > 180)
                _self.map.units = 'm';
            var geo = null;
            for (var j = 0; j < qks.length; j++) {
                var points = qks[j];
                if (points != null && points.length > 0) {
                    var lin = new SuperMap.Geometry.LinearRing();
                    for (var i = 0; i < points.length; i++) {
                        var p = new SuperMap.Geometry.Point(points[i].x, points[i].y);
                        lin.addComponent(p, i);
                    }
                    if (geo == null) geo = new SuperMap.Geometry.Polygon(lin);
                    else geo.addComponent(lin);
                }
            }
            if (!_self.isVectorLayerAdded) {
                addVectorLayer();
            }
            else {
                for (var i = 0; i < _self.vectorLayer.features.length; i++) {
                    if (_self.vectorLayer.features[i]["tag"] != null && _self.vectorLayer.features[i]["tag"] == tag) {
                        _self.vectorLayer.features[i].destroy();
                    }
                }

            }
            geo.calculateBounds()
            var feature = new SuperMap.Feature.Vector(geo);
            var features = new Array();
            feature.style = style2;
            feature["tag"] = tag;
            features[0] = feature;
            _self.vectorLayer.addFeatures(features);
            var bds = _self.map.getMaxExtent();

            var bounds = geo.bounds.scale(5);
            if (bds == null)
                bds = bounds;
            else
                bds.extend(bounds);

            if (bds.left < 0 || bds.left > bounds.left) {
                bds.left = bounds.left;
            }

            if (bds.right < bounds.right) {
                bds.right = bounds.right;
            }

            if (bds.top < bounds.top) {
                bds.top = bounds.top;
            }

            if (bds.bottom < 0) {
                bds.bottom = bounds.bottom;
            }

            _self.map.restrictedExtent = bds;
            _self.map.maxExtent = bds;
            _self.map.zoomToExtent(bounds, true);
        }
    }
    this.addGeometryEx2 = function (featureex)//sfPoint数组
    {
        var feature = featureex.clone();
        if (feature != null) {

            feature["tag"] = "useradd";
            if (!_self.isVectorLayerAdded) {
                addVectorLayer();
            }
            else {
                for (var i = 0; i < _self.vectorLayer.features.length; i++) {
                    if (_self.vectorLayer.features[i]["tag"] != null && _self.vectorLayer.features[i]["tag"] == "useradd") {
                        _self.vectorLayer.features[i].destroy();
                    }
                }

            }
            var geo = feature.geometry;
            var features = new Array();
            feature.style = style2;
            features[0] = feature;
            _self.vectorLayer.addFeatures(features);
            var bds = _self.map.getMaxExtent();
            geo.calculateBounds();
            var bounds = geo.bounds.scale(5);
            if (bds == null)
                bds = bounds;
            else
                bds.extend(bounds);
            _self.map.restrictedExtent = bds;
            _self.map.maxExtent = bds;
            _self.map.zoomToExtent(bounds, true);
        }
    }


    function hasClass(element, className) {
        var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
        return element.className.match(reg);
    }
    function addClass(element, className) {
        if (!hasClass(element, className)) {
            element.className += " " + className;
        }
    }
    function removeClass(element, className) {
        if (hasClass(element, className)) {
            var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
            element.className = element.className.replace(reg, ' ');
        }
    }

    this.setMapVisibility = function (mapName, visibility) {
        for (i = _self.map.layers.length - 1; i >= 0; i--) {
            if (_self.map.layers[i].name == mapName) {
                _self.map.layers[i].setVisibility(visibility);
                //                layer.events.on({ "layerInitialized": afterLayerInitialized });
            }
        }
    }
}
